package com.tiorb.socket;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

import com.tiorb.socketlibrary.SocketConnect;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    EditText ip, port;
    Button connect, disconnect,send;
    SocketConnect socketConnect;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        socketConnect = new SocketConnect(this);
        initViews();
    }

    private void initViews() {
        ip = findViewById(R.id.ip);
        port = findViewById(R.id.port);
        send = findViewById(R.id.send);
        connect = findViewById(R.id.connect);
        disconnect = findViewById(R.id.disconnect);
        socketConnect.setAddress(ip.getText().toString(),Integer.valueOf(port.getText().toString()));
        socketConnect.initSocket();
        connect.setOnClickListener(this::onClick);
        disconnect.setOnClickListener(this::onClick);
        send.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.connect:
                socketConnect.Connect();
                break;
            case R.id.disconnect:
                socketConnect.disConnect();
                break;
            case R.id.send:
                socketConnect.send("1234556");
                break;
            default:
                break;
        }
    }
}